﻿namespace WebServiceExtensions.CallCounterExtension
{
	#region Namespaces

	using System;
	using System.Collections.Generic;

	#endregion

	/// <summary>
	///   TODO: Update summary.
	/// </summary>
	public class CallCounterKey : IEquatable<CallCounterKey>
	{
		#region Constructors (2) 

		/// <summary>
		///   Initializes a new instance of the <see cref = "CallCounterKey" /> class.
		/// </summary>
		/// <param name = "type">
		///   The type.
		/// </param>
		/// <param name = "method">
		///   The method.
		/// </param>
		public CallCounterKey(string type, string method)
		{
			this.Type = type;
			this.Method = method;
		}

		/// <summary>
		///   Initializes a new instance of the <see cref = "CallCounterKey" /> class.
		/// </summary>
		public CallCounterKey()
		{
		}

		#endregion Constructors 

		#region Properties (2) 

		/// <summary>
		///   Gets or sets the method.
		/// </summary>
		/// <value>
		///   The method.
		/// </value>
		public string Method { get; set; }

		/// <summary>
		///   Gets or sets the type.
		/// </summary>
		/// <value>
		///   The type.
		/// </value>
		public string Type { get; set; }

		#endregion Properties 

		#region Methods (3) 

		// Public Methods (3) 

		/// <summary>
		///   Indicates whether the current object is equal to another object of the same type.
		/// </summary>
		/// <param name = "other">
		///   An object to compare with this object.
		/// </param>
		/// <returns>
		///   true if the current object is equal to the other parameter; otherwise, false.
		/// </returns>
		public bool Equals(CallCounterKey other)
		{
			return string.Compare(this.Method, other.Method, StringComparison.OrdinalIgnoreCase) == 0
			       && string.Compare(this.Type, other.Type, StringComparison.OrdinalIgnoreCase) == 0;
		}

		/// <summary>
		///   Determines whether the specified <see cref = "System.Object" /> is equal to this instance.
		/// </summary>
		/// <param name = "obj">
		///   The <see cref = "System.Object" /> to compare with this instance.
		/// </param>
		/// <returns>
		///   <c>true</c> if the specified <see cref = "System.Object" /> is equal to this instance; otherwise, <c>false</c>.
		/// </returns>
		public override bool Equals(object obj)
		{
			return this.Equals(obj as CallCounterKey);
		}

		/// <summary>
		///   Returns a hash code for this instance.
		/// </summary>
		/// <returns>
		///   A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
		/// </returns>
		public override int GetHashCode()
		{
			return string.Concat(this.Method, this.Type).GetHashCode();
		}

		#endregion Methods 

		#region Nested Classes (1) 

		/// <summary>
		///   Equality comparer for Call Counter
		/// </summary>
		public class EqualityComparer : IEqualityComparer<CallCounterKey>
		{
		#region Methods (2) 

		// Public Methods (2) 

			/// <summary>
			///   Determines whether the specified objects are equal.
			/// </summary>
			/// <param name = "x">
			///   The first object of type T to compare.
			/// </param>
			/// <param name = "y">
			///   The second object of type T to compare.
			/// </param>
			/// <returns>
			///   true if the specified objects are equal; otherwise, false.
			/// </returns>
			public bool Equals(CallCounterKey x, CallCounterKey y)
			{
				return string.Compare(x.Method, y.Method, StringComparison.OrdinalIgnoreCase) == 0
				       && string.Compare(x.Type, y.Type, StringComparison.OrdinalIgnoreCase) == 0;
			}

			/// <summary>
			///   Returns a hash code for this instance.
			/// </summary>
			/// <param name = "obj">
			///   The obj.
			/// </param>
			/// <returns>
			///   A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
			/// </returns>
			/// <exception cref = "T:System.ArgumentNullException">
			///   The type of obj is a reference type and obj is null.
			/// </exception>
			public int GetHashCode(CallCounterKey obj)
			{
				return string.Concat(obj.Method, obj.Type).GetHashCode();
			}

		#endregion Methods 
		}
		#endregion Nested Classes 
	}
}